package com.naiterui.ehp.bs.doctor.dao.impl;

import com.naiterui.ehp.bs.doctor.dao.IDrAppH5MapperDao;
import com.naiterui.ehp.bs.doctor.domain.DrAppH5Mapper;
import com.naiterui.ehp.bs.doctor.repository.IDrAppH5MapperRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;

/**
 * <pre>app与h5配置数据操作</pre>
 *
 * @author gongbaoqiang
 * @date 2019/7/15 16:37
 * @since 1.0.0
 */
@Component
public class AdDrAppH5MapperDaoImpl  implements IDrAppH5MapperDao {

    @Autowired
    private IDrAppH5MapperRepository drAppH5MapperRepository;

    @Override
    public void save(DrAppH5Mapper drAppH5Mapper) {
        drAppH5MapperRepository.save(drAppH5Mapper);
    }

    @Override
    public DrAppH5Mapper findPreByAppVersionAndDeviceTyp(String appV, Integer type) {
        Sort sort = Sort.by(Sort.Direction.DESC, "appVersion", "h5Version");
        return drAppH5MapperRepository.findFirstByAppVersionLessThanEqualAndDeviceType(appV, type, sort);
    }

    @Override
    public DrAppH5Mapper findNewsOne() {
        return drAppH5MapperRepository.findAll(Sort.by("h5Version").descending()).iterator().next();
    }
}
